package lex.fsm;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

public abstract class AbstractTransition implements Transition {
	private final State nextState;

	/**
	 * Creates a new instance with the specified {@link State} as next state and
	 * for the specified {@link StateEvent} id.
	 * 
	 * @param eventId
	 *            the {@link StateEvent} id.
	 * @param nextState
	 *            the next {@link State}.
	 */
	public AbstractTransition(State nextState) {
		this.nextState = nextState;
	}

	public State getNextState() {
		return nextState;
	}

	public abstract boolean accept(StateEvent event);

	public boolean equals(Object o) {
		if (!(o instanceof AbstractTransition)) {
			return false;
		}
		if (o == this) {
			return true;
		}
		AbstractTransition that = (AbstractTransition) o;
		return new EqualsBuilder().append(nextState, that.nextState).isEquals();
	}

	public int hashCode() {
		return new HashCodeBuilder(11, 31).append(nextState).toHashCode();
	}

	public String toString() {
		return new ToStringBuilder(this).append("nextState", nextState).toString();
	}
}
